import {Events} from "@tarojs/taro";


class Event {
    event: TaroGeneral.Events

    constructor() {
        this.event = new Events();
    }

    /**
     * 监听一个事件，接受参数
     */
    on(eventName: string, listener: (...args: any[]) => void): TaroGeneral.Events {
        return this.event.on(eventName, listener);
    }

    /**
     * 添加一个事件监听，并在事件触发完成之后移除Callbacks链
     */
    once(eventName: string, listener: (...args: any[]) => void): TaroGeneral.Events {
        return this.event.once(eventName, listener);
    }

    /**
     * 取消监听一个事件
     */
    off(eventName: string, listener?: (...args: any[]) => void): TaroGeneral.Events {
        return this.event.off(eventName, listener);
    }

    /**
     * 取消监听的所有事件
     */
    offAll(): TaroGeneral.Events {
        return this.event.off();
    }

    /**
     * 触发一个事件，传参
     */
    trigger(eventName: string, ...args: any[]): TaroGeneral.Events {
        return this.event.trigger(eventName, ...args);
    }
}


export default new Event()
